package com.sinba.common.business.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.sinba.common.business.dto.BuyDTO;
import com.sinba.common.business.dto.BuyQueryDTO;
import com.sinba.common.business.dto.SellDTO;
import com.sinba.common.business.dto.SellQueryDTO;
import com.sinba.common.business.service.IBuyService;
import com.sinba.common.business.service.ISellService;
import com.sinba.common.dto.PageDTO;

@SuppressWarnings("serial")
public class SellAction extends ActionSupport{
	@Autowired
	private ISellService sellService;
	
	private String sord;
    private String sidx;
    private int page = 1;
    private int rows = 10;
    
	private PageDTO pageDTO;
	private SellDTO sellDTO = new SellDTO();
	private SellQueryDTO sellQueryDTO = new SellQueryDTO();
	private Long[] ids;
	private String resultStr;
	private String pageUrl;
	public String getSord() {
		return sord;
	}
	public void setSord(String sord) {
		this.sord = sord;
	}
	public String getSidx() {
		return sidx;
	}
	public void setSidx(String sidx) {
		this.sidx = sidx;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	public PageDTO getPageDTO() {
		return pageDTO;
	}
	public void setPageDTO(PageDTO pageDTO) {
		this.pageDTO = pageDTO;
	}
	public SellDTO getSellDTO() {
		return sellDTO;
	}
	public void setSellDTO(SellDTO sellDTO) {
		this.sellDTO = sellDTO;
	}
	public SellQueryDTO getSellQueryDTO() {
		return sellQueryDTO;
	}
	public void setSellQueryDTO(SellQueryDTO sellQueryDTO) {
		this.sellQueryDTO = sellQueryDTO;
	}
	public Long[] getIds() {
		return ids;
	}
	public void setIds(Long[] ids) {
		this.ids = ids;
	}
	public String getResultStr() {
		return resultStr;
	}
	public void setResultStr(String resultStr) {
		this.resultStr = resultStr;
	}
	public String getPageUrl() {
		return pageUrl;
	}
	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}
	/**
	 * 分页查询
	 * @return
	 */
	public String findSellPage(){
		
		int start = ( page - 1 ) * rows;
		sellQueryDTO.setStart( start );
		sellQueryDTO.setLimit( rows );
		pageDTO = sellService.findSellPage( sellQueryDTO, sord, sidx );
		
		if ( pageDTO != null )
		{
		    pageDTO.setPage( page );
		    pageDTO.setRows( rows );
		}
		return SUCCESS;
	}
	
	public String sellBack(){
		resultStr = sellService.save(sellDTO);
		return SUCCESS;
	}
	
	/**
	 * 卖出
	 * @return
	 */
	public String sell(){
		if(pageUrl==null || pageUrl==""){
			pageUrl="index.jsp";
		}
		resultStr = sellService.save(sellDTO);
		return "optresult";
	}
	/**
	 * 取消
	 * @return
	 */
	public String clean(){
		if(pageUrl==null || pageUrl==""){
			pageUrl="index.jsp";
		}
		resultStr = sellService.clean(sellDTO);
		return "optresult";
	}
	
	public String changeOrder(){
		sellService.changeOrder(sellDTO);
		return SUCCESS;
	}
}
